package frame;

import clsaa.Biglotto;
import data.ConfigBigLotto;

import javax.swing.*;
import java.awt.*;

public class lishiDatafenxiFrame  extends JFrame {
    static JPanel  dataShow;
    public void initdataShow(){
        if(dataShow != null)dataShow.removeAll();
        dataShow.setBounds(0,0,400,480);
        // 创建一个滚动面板
        JScrollPane scrollPane = new JScrollPane();

        // 创建一个JTextArea用于显示文本
        JTextArea textArea = new JTextArea();
        textArea.setEditable(false); // 设置文本区域为不可编辑
        textArea.setLineWrap(true); // 设置自动换行
        textArea.setWrapStyleWord(true); // 设置在单词边界处换行
        // 将JTextArea添加到滚动面板中
        scrollPane.setViewportView(textArea);

        ConfigBigLotto configBigLotto=new ConfigBigLotto();
        configBigLotto.getAllbiglotto().initDataNum();

        textArea.append("历史数据分析中。。。\n");
        textArea.append("存在历史数据从"+configBigLotto.getAllbiglotto().getAllData().get(configBigLotto.getAllbiglotto().getAllData().size()-1).getDate()+"到"+configBigLotto.getAllbiglotto().getAllData().get(0).getDate()+"共有"+configBigLotto.getAllbiglotto().getAllData().size()+"条数据\n");
        textArea.append("其中前区号码出现的概率从大到小依次为：\n");
        int[] numA=new int[35];
        for(int i=0;i<35;++i){
            numA[i]=i+1;
        }
        int[] numB=new int[12];
        for(int i=0;i<12;++i){
            numB[i]=i+1;
        }
        for(int i=0;i<34;++i){
            for(int j=i+1;j<35;++j){
                if(configBigLotto.getAllbiglotto().getDataA()[i]<configBigLotto.getAllbiglotto().getDataA()[j]){
                    int v=configBigLotto.getAllbiglotto().getDataA()[i];
                    configBigLotto.getAllbiglotto().getDataA()[i]=configBigLotto.getAllbiglotto().getDataA()[j];
                    configBigLotto.getAllbiglotto().getDataA()[j]=v;
                    v=numA[i];
                    numA[i]=numA[j];
                    numA[j]=v;
                    double bb=configBigLotto.getAllbiglotto().getDataAV()[i];
                    configBigLotto.getAllbiglotto().getDataAV()[i]=configBigLotto.getAllbiglotto().getDataAV()[j];
                    configBigLotto.getAllbiglotto().getDataAV()[j]=bb;
                }
            }
        }
        for(int i=0;i<35;++i){
            textArea.append("号码"+numA[i]+"  出现次数："+configBigLotto.getAllbiglotto().getDataA()[i]+"  出现概率:"+configBigLotto.getAllbiglotto().getDataAV()[i]+"\n");
        }
        textArea.append("其中后区号码出现的概率从大到小依次为：\n");
        for(int i=0;i<11;++i){
            for(int j=i+1;j<12;++j){
                if(configBigLotto.getAllbiglotto().getDataB()[i]<configBigLotto.getAllbiglotto().getDataB()[j]){
                    int v=configBigLotto.getAllbiglotto().getDataB()[i];
                    configBigLotto.getAllbiglotto().getDataB()[i]=configBigLotto.getAllbiglotto().getDataB()[j];
                    configBigLotto.getAllbiglotto().getDataB()[j]=v;
                    v=numB[i];
                    numB[i]=numB[j];
                    numB[j]=v;
                    double bb=configBigLotto.getAllbiglotto().getDataBV()[i];
                    configBigLotto.getAllbiglotto().getDataBV()[i]=configBigLotto.getAllbiglotto().getDataBV()[j];
                    configBigLotto.getAllbiglotto().getDataBV()[j]=bb;
                }
            }
        }
        for(int i=0;i<12;++i){
            textArea.append("号码"+numB[i]+"  出现次数："+configBigLotto.getAllbiglotto().getDataB()[i]+"  出现概率:"+configBigLotto.getAllbiglotto().getDataBV()[i]+"\n");
        }
        // 创建一个主面板并使用BorderLayout
        dataShow.add(scrollPane, BorderLayout.CENTER);
        add(dataShow);

        dataShow.updateUI();
    }
    public lishiDatafenxiFrame(){
        super("历史数据分析");
        // 设置窗口关闭操作
        setDefaultCloseOperation(2);
        // 设置窗口大小
        setSize(400, 500);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

        // 计算JFrame的左上角应该放在屏幕上的位置
        int x = (screenSize.width - this.getWidth()) / 2;
        int y = (screenSize.height - this.getHeight()) / 2;

        // 设置JFrame的位置
        this.setLocation(x, y);
        setLayout(null);
        dataShow=new JPanel(new BorderLayout());
        initdataShow();
        add(dataShow);
        setVisible(true);
    }
    public static void main(String[] args) {
        // 创建并显示窗口
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new lishiDatafenxiFrame();
            }
        });
    }
}
